package com.jackwoo.jerrymouse.socket;

import com.jackwoo.jerrymouse.logger.SocketLogger;

import java.io.IOException;
import java.net.ServerSocket;

/**
 * Author: StupidZhe
 * Date: 2019/11/19
 * Desc:
 **/
public class JerryMouseSocket extends ServerSocket {

    public static final int DEFAULT_PORT = 8080;
    public static int PORT = DEFAULT_PORT;

    private volatile static JerryMouseSocket jerryMouseSocket;

    // singleton pattern
    public static JerryMouseSocket getInstance() {
        if (jerryMouseSocket == null) {
            synchronized (JerryMouseSocket.class) {
                try {
                    if (jerryMouseSocket == null) {
                        jerryMouseSocket = new JerryMouseSocket();
                    }
                } catch (IOException e) {
                    e.printStackTrace();
                    SocketLogger.getInstance().error(e.getMessage());
                }
            }
        }
        return jerryMouseSocket;
    }

    private JerryMouseSocket() throws IOException {
        super(PORT);
    }

    private JerryMouseSocket(int port) throws IOException {
        super(port);
    }

    private JerryMouseSocket(int port, int backlog) throws IOException {
        super(port, backlog);
    }
}
